{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%reload_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import sys\n",
    "sys.path.append(os.path.abspath('../'))\n",
    "from common import *\n",
    "\n",
    "fig_name = 'indirect_reparam'\n",
    "fig_dir = join(FIGURE_DIR, fig_name)\n",
    "\n",
    "from indirect_reparam import results\n",
    "\n",
    "fontsize = 12\n",
    "n_rows = 2 * len(results) \n",
    "n_cols = 3\n",
    "total_width = COLUMN_WIDTH\n",
    "aspect = n_rows / n_cols\n",
    "\n",
    "fig = plt.figure(1, figsize=(total_width, aspect * total_width), constrained_layout=False)\n",
    "gs = fig.add_gridspec(n_rows, n_cols, wspace=0.025, hspace=0.025)\n",
    "row = 0\n",
    "title_offset = 1.07\n",
    "\n",
    "names = ['Reference', 'No secondary gradients', 'With secondary gradients']\n",
    "crops = [(135, 135, 70, 200), (100, 100, 100, 100)]\n",
    "for result, crop in zip(results, crops):\n",
    "    scene_name = result['scene']\n",
    "    scene_configs = result['configs']\n",
    "\n",
    "\n",
    "    col = 0\n",
    "    ax = fig.add_subplot(gs[row, col])\n",
    "    img = read_img(join(fig_dir, scene_name, 'ref.exr'))\n",
    "    img = img[crop[0]:-crop[1], crop[2]:-crop[3], :]\n",
    "    ax.imshow(img, interpolation='none')\n",
    "    disable_ticks(ax)\n",
    "    if row == 0:\n",
    "        txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "    ax.set_ylabel('Optimization view', labelpad=5, fontsize=fontsize)\n",
    "    col += 1\n",
    "    for config in scene_configs:\n",
    "        ax = fig.add_subplot(gs[row, col])\n",
    "        img = read_img(join(fig_dir, scene_name, f'{config.name}-0.exr'))\n",
    "        aspect = img.shape[0] / img.shape[1]\n",
    "        img = img[crop[0]:-crop[1], crop[2]:-crop[3], :]\n",
    "        ax.imshow(img, interpolation='none')\n",
    "        disable_ticks(ax)\n",
    "        if row == 0:\n",
    "            txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "        col += 1\n",
    "\n",
    "    row += 1\n",
    "    col = 0\n",
    "    ax = fig.add_subplot(gs[row, col])\n",
    "    img = read_img(join(fig_dir, scene_name, 'geo-ref.exr'))\n",
    "    ax.imshow(img, interpolation='none')\n",
    "    disable_ticks(ax)\n",
    "    ax.set_ylabel('Geometry (novel view)', labelpad=5, fontsize=fontsize)\n",
    "    if row == 0:\n",
    "        txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "    col += 1\n",
    "    for config in scene_configs:\n",
    "        ax = fig.add_subplot(gs[row, col])\n",
    "        img = read_img(join(fig_dir, scene_name, f'{config.name}-1.exr'))\n",
    "        aspect = img.shape[0] / img.shape[1]\n",
    "        ax.imshow(img, interpolation='none')\n",
    "        disable_ticks(ax)\n",
    "        if row == 0:\n",
    "            txt = ax.set_title(names[col], fontsize=fontsize, va='top', y=title_offset)\n",
    "        col += 1\n",
    "    row += 1\n",
    "\n",
    "plt.margins(0, 0)\n",
    "# save_fig(fig_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('mi')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "c8cc192903caa17681aa39d71202092ac11a526d37a1c4ad2948f13605924304"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
